#pragma once
/**
 * @file event_protoco.h
 * @brief 协议序列化基础类
 * @copyright Copyright (c) 2020 YUSUR Technology Co., Ltd. All Rights Reserved. Learn more at www.yusur.tech.
 * @author liuzx@yusur.tech
 * @date 2023-07-13
 */

#include <sstream>
#include <string>
#include <vector>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>

namespace YuSur_Serializate
{
template <class T>
void Serialization_Helper(const T& t, std::ostringstream& ostream)
{
    boost::archive::binary_oarchive oa(ostream);
    oa << t;
}
template <class T>
void UnSerialization_Helper(T& t, std::istringstream& istream)
{
    boost::archive::binary_iarchive ia(istream);
    ia >> t;
}

template <class T>
void Serialization_Text_Helper(const T& t, std::ostringstream& ostream)
{
    boost::archive::text_oarchive oa(ostream);
    oa << t;
}
template <class T>
void UnSerialization_Text_Helper(T& t, std::istringstream& istream)
{
    boost::archive::text_iarchive ia(istream);
    ia >> t;
}

}  // namespace YuSur_Serializate

#define RECV_BUF_LEN (4096)
#ifdef WIN32
#define RECV_BUF_HEAD (61)
#else
#define RECV_BUF_HEAD (74)
#endif

#pragma pack(push, 1)
struct PackHead
{
    int nVersion;
    int nType;
    int nSeqID;
    int nLen;
    template <typename Ar>
    void serialize(Ar& ar, const unsigned int version)
    {
        ar& nVersion& nType& nSeqID& nLen;
    }
};
#pragma pack(pop)

#define MSGID_HEARTBEAT 1
#pragma pack(push, 1)
struct HeartBeat
{
    uint64_t timestamp;
    template <typename Ar>
    void serialize(Ar& ar, const unsigned int version)
    {
        ar& timestamp;
    }
};
#pragma pack(pop)
/**
 * @brief 接受数据回调处理
 */
struct IRecvData
{
    /**
 　　* @brief 原始数据回调
 　　*/
    virtual void onRecv(const char* pData, int nLen){};
    /**
 　　* @brief 序列化头数据回调，pdata数据未序列化
 　　*/
    virtual void onRecv(PackHead* pHead, const char* pData, int nLen){};
};

enum EventMsgType
{
    kHeartBeatReq  = 1,
    kHeartBeatResp = 2
};
